<?php
namespace app\api\controller\supplier\traits;
use app\modules\supplier\logic\LoginLogic;

trait LoginGrid{
    protected $prefix = ''; //前缀
    protected $rule_action = ['index', 'create', 'save', 'edit', 'update', 'read', 'delete']; //允许访问方法列表
    protected $logic;

    public function __construct()
    {
        parent::__construct();
        $this->logic = new LoginLogic();
    }

    protected function _beforeEmpty($action = '')
    {
        if ($this->prefix != '' && false !== strpos($action, $this->prefix)) {
            $action = str_replace($this->prefix, '', $action);
            if (in_array($action, $this->rule_action) && method_exists($this, $action)) {
                return call_user_func([$this, $action]);
            } else {
                return false;
            }
        } else {
            return false;
        }

    }

    public function index(){

       $option = [
            'peer_member_status' => $this->getParams('peer_member_status', 1, 'intval'),//同行人状态
            'is_pages' => ($this->getParams('is_pages', 0, 'intval') >= 1 ? true : false),//是否分页查询
            'page_current' => $this->getParams('page_current', 1, 'intval'),//分页查询时，当前页码
            'page_size' => $this->getParams('page_size', 10, 'intval'),
            'keyword' => $this->getParams('keyword', '', 'trim,strip_tags'),
            'order' => $this->getParams('order', 'ASC', 'trim,strip_tags,strtoupper'),
            'sort' => $this->getParams('sort', '', 'trim,strip_tags')//排序字段
        ];

        if ($option['page_current'] < 1) {
            $option['page_current'] = 1;
        }

        $data = $this->logic->index($option);
        // dump($data);
        if (is_array($data)) {
            return $this->apiSuccess($data);
        }else{
            return $this->apiError($this->logic->getError());
        }
    	
    	// return $this->apiError('请求超时');
    }
}
